var app = new Vue({
    el: '#badge',
    data() {
        return {
            number: "",
            role:""
        }
    },
    mounted() {
        this.getNumber();
    },
    methods: {
        getNumber() {
            var $this = this;
            $.ajax({
                url:"/message/getMsgNmber",
                dataType: "json",
                type:"get",
                async: "false",
                success(data){
                    if (vm){
                        vm.number = data.data.msgNmber;
                    }
                },
                error(){

                }
            })
        }
    }
})


$(function () {
    var $this = this;
    $.ajax({
        url: "/user/info",
        type: "GET",
        async: false,
        success: function (data) {

            console.log(data);
            if (data.code == 200) {
                if(data.data.user.role==1){
                    //学生
                    $("#user-name").text(data.data.user.studentName);
                    app.role = 1;
                    //nac.roles = 1;
                    if(vm){
                        vm.rolee = 1;
                    }
                    vm.rolee = 1;
                }else if(data.data.user.role==2){
                    //老师
                    if(data.data.user.isAdmin == 0){
                        $("#user-name").text(data.data.user.teacherName);
                        //app.isAdmin = data.data.user.isAdmin;
                        app.role = 0;
                        //nac.roles = 2;
                        if(vm){
                            vm.rolee = 0;
                        }
                    }else if(data.data.user.isAdmin == 1){
                        $("#user-name").text(data.data.user.teacherName);
                        //app.isAdmin = data.data.user.isAdmin;
                        app.role = 2;
                        //nac.roles = 2;
                        if(vm){
                            vm.rolee = 2;
                        }
                    }
                }
                console.log("当前登录"+data.data.user.role)
            } else {
                alert("出现错误！");
            }
        },
        error: function (data) {
            console.log(data.message);
        }
    })
});

//退出登录
$("#logout").click(function(){
    $.ajax({
        url: "/user/logout",
        type: "GET",
        async: false,
        success: function (data) {
            if (data.code == 200) {
                location.replace("/dayday/login/index.html");
            } else {
                alert("出现错误！");
            }
        },
        error: function (data) {
            console.log(data.message);
        }
    })
});